package com.apiserver.kernel.result;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author feizhou
 * @Description 这个方法有什么用
 * @Date 下午 10:30 2019/10/14 0014
 * @Param 
 * @return 
 **/

public enum StatusCode {

    OK(200, "服务器成功返回用户请求的数据."),
    //用户新建或修改数据成功
    CREATED(201,"执行操作成功"),

    ;

    private static final Map<Integer, StatusCode> CODE_MAP = new HashMap<Integer, StatusCode>();

    static {
        for (StatusCode typeEnum : StatusCode.values()) {
            CODE_MAP.put(typeEnum.getCode(), typeEnum);
        }
    }
    StatusCode(Integer code, String meaning) {
        this.code = code;
        this.meaning = meaning;
    }
    public Integer getCode() {
        return code;
    }

    public String getMeaning() {
        return meaning;
    }

    public static StatusCode getEnum(Integer code) {

        return CODE_MAP.get(code);
    }
    private final Integer code;
    private final String meaning;

    public static StatusCode valueOf(Integer code) {
        if (code == null) {
            throw new IllegalArgumentException("valueOf - param code is null.");
        }
        StatusCode result = null;
        for (StatusCode statusCodeEnum : StatusCode.values()) {
            if (statusCodeEnum == null) {
                continue;
            }
            if (code.equals(statusCodeEnum.getCode())) {
                result = statusCodeEnum;
                break;
            }
        }
        if (result == null) {
            throw new IllegalStateException("can not find the enum item with code " + code);
        }
        return result;
    }
}
